/***************************************************************************
 * Copyright 2012-2013 TXT e-solutions SpA
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * This work was performed within the IoT_at_Work Project
 * and partially funded by the European Commission's
 * 7th Framework Programme under the contract ICT-257367.
 *
 * Authors:
 *      Salvatore Piccione (TXT e-solutions SpA)
 *
 * Contributors:
 *        Domenico Rotondi (TXT e-solutions SpA)
 **************************************************************************/
package it.txt.ens.client.gui.standalone.util;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class ApplicationPropertiesRepository {
	
	private static final String PROPERTY_NAME_PREFIX = "ens.client.";
	private static final String CER_PROPERTY_NAME_PREFIX = PROPERTY_NAME_PREFIX + "cer.";
	private static final String RESOURCE_URI_PROPERTY_NAME_PREFIX = PROPERTY_NAME_PREFIX + "resourceURI.";
	
	public static final String EXCHANGE_NAME = PROPERTY_NAME_PREFIX + "exchange";
	public static final String QUEUE_NAME = PROPERTY_NAME_PREFIX + "queue";
	public static final String ROUTING_KEY = PROPERTY_NAME_PREFIX + "routingKey";
	
	public static final String USERNAME = PROPERTY_NAME_PREFIX + "usr";
	public static final String PASSWORD = PROPERTY_NAME_PREFIX + "pwd";
	public static final String VIRTUAL_HOST = PROPERTY_NAME_PREFIX + "vHost";
	
	public static final String SCHEMAS_DIR = PROPERTY_NAME_PREFIX + "schemasDir";
	public static final String KEYSTORE = PROPERTY_NAME_PREFIX + "keystore";
	
	public static final String KEYSTORE_PWD = PROPERTY_NAME_PREFIX + "keystore.pwd";
	public static final String PRIVATE_KEY_PWD = CER_PROPERTY_NAME_PREFIX + "privateKey.pwd";
	public static final String CAPABILITY_DIR = PROPERTY_NAME_PREFIX + "capability.dir";
	
	public static final String RESOURCE_URI_SCHEME = RESOURCE_URI_PROPERTY_NAME_PREFIX + "scheme";
	public static final String RESOURCE_URI_AUTHORITY = RESOURCE_URI_PROPERTY_NAME_PREFIX + "authority";
	public static final String RESOURCE_URI_SERVICE = RESOURCE_URI_PROPERTY_NAME_PREFIX + "service";
	
	public static final String DEFAULT_DATA_URI = PROPERTY_NAME_PREFIX + "defaultDataURIs";
	
	public static Properties APPLICATION_PROPERTIES = new Properties();
	
	public static void initProperties (String propertiesPath) throws IOException {
		BufferedInputStream iStream = null;
		try {
			iStream = new BufferedInputStream(
				new FileInputStream(new File (propertiesPath)));
			APPLICATION_PROPERTIES.load(iStream);
		} finally {
			if (iStream != null)
				iStream.close();
		}
	}

}
